import time
from wordpress_project.base.page_operation import PageTools


class login(PageTools):   # 继承类，是一个总类
    login_url = "http://192.168.0.125:9009/wp-login.php"    # 登录页面地址
    username_ele = '[id="user_login"]'                      # 用户名元素css定位
    password_ele = '[id="user_pass"]'                       # 密码元素css定位
    login_button_ele = '[name="wp-submit"]'                 # 登录按钮的css定位
    login_success_ele = '[id="wp-admin-bar-my-account"] a'
    login_false_ele = '[id="login_error"]'


    def login_action(self, username, password):
        self.visit(self.login_url)                          # 进入登录页面
        time.sleep(1)
        self.refresh()
        self.by_css(self.username_ele).send_keys(username)  # 输入用户名
        time.sleep(1)
        self.by_css(self.password_ele).send_keys(password)  # 输入密码
        time.sleep(1)
        self.by_css(self.login_button_ele).click()          # 点击登录按钮
        time.sleep(1)

    def get_success_text(self):
        return self.by_css(self.login_success_ele).text
    def get_false_text(self):
        return self.by_css(self.login_false_ele).text


